home *** CD-ROM | disk | FTP | other *** search
/ IRIX Patches 1995 June / SGI IRIX Patches 1995 Jun.iso / 5.3_patches / patchSG0000154 / patchSG0000154.idb / usr / share / src / OpenGL / exts / varray.c.z / varray.c
Encoding:
C/C++ Source or Header  |  1995-06-12  |  16.1 KB  |  629 lines

  1. /*
  2.  * (c) Copyright 1993, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED 
  4.  * Permission to use, copy, modify, and distribute this software for 
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that 
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission. 
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  * 
  25.  * US Government Users Restricted Rights 
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36.  */
  37.  
  38. /* vertarr.c
  39. ** This program demonstrates using the vertex array extension.
  40. ** it uses vertex array in immediate mode, and in display lists.
  41. ** "a" toggles vertex arrays
  42. ** "d" toggles display lists
  43. ** "m" toggles between compile and compile and execute mode
  44. **      (works only if display lists are on)
  45. */
  46.  
  47. #include <stdio.h>
  48. #include <string.h>
  49. #include <stdlib.h>
  50. #include "tk.h"
  51. #include "math.h"
  52.  
  53.  
  54. #define COLOR_OFFSET_1    16
  55. #define COLOR_OFFSET_2    32
  56.  
  57. #define CHECK_ERROR  err = glGetError(); \
  58.     if (err) printf("Error %d at line %d\n", err, __LINE__);
  59.  
  60. static GLubyte texture [768];
  61.  
  62. static GLint verts[] = {
  63.     10, 10, 0,
  64.     200, 100, 0,
  65.     50, 200, 0 };
  66.  
  67. static GLfloat colors[] = {
  68.     1.0, 0.0, 0.0,
  69.     0.0, 0.0, 1.0,
  70.     0.5, 0.2, 0.8 };
  71.  
  72. static GLfloat cv[] = { 
  73.     1.0, 1.0, 0.0,
  74.     430, 30,
  75.     1.0, 0.0, 1.0,
  76.     480, 300,
  77.     1.0, 1.0, 1.0,
  78.     380, 200 };
  79.  
  80. static GLshort tv[] = {
  81.     0, 0,
  82.     5, 400,
  83.     1, 0,
  84.     100, 400,
  85.     1, 1,
  86.     100, 495,
  87.     0, 1,
  88.     5, 495 };
  89.  
  90. static GLfloat verts2[] = {
  91.     350.0, 450.0, 1.0, 1.0,
  92.     350.0, 350.0, 1.0, 1.0,
  93.     400.0, 325.0, 1.0, 1.0,
  94.     450.0, 350.0, 1.0, 1.0,
  95.     450.0, 450.0, 1.0, 1.0,
  96.     400.0, 475.0, 1.0, 1.0 };
  97.  
  98. static GLfloat norms[] = {
  99.     0, 0, 1, 
  100.     0, 0, 1, 
  101.     0, 0, 1, 
  102.     0, 0, 1,
  103.     0, 0, -1, 
  104.     0, 0, -1, 
  105.     0, 0, -1, 
  106.     0, 0, -1 };
  107.  
  108. static GLint verts3[] = { 
  109.     150, 200, 
  110.     250, 200, 
  111.     250, 300, 
  112.     150, 300, 
  113.     250, 200, 
  114.     350, 200, 
  115.     350, 300, 
  116.     250, 300 };
  117.  
  118. static GLboolean edges[] = {
  119.     GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE };
  120.  
  121. GLenum rgb, directRender, err;
  122. int drawArray = 0;
  123. int dlist = 0; /* 0 = immediate mode, ~0 = display list */
  124. GLenum dlMode = GL_COMPILE;
  125.  
  126.  
  127. static void SetUpColorMap(void)
  128. {
  129.     long i;
  130.  
  131.     for (i = 0; i < 16; i++) {
  132.     tkSetOneColor(i+COLOR_OFFSET_1, 0.0, 0.0, i/15.0);
  133.     tkSetOneColor(i+COLOR_OFFSET_2, 0.0, i/15.0, 0.0);
  134.     }
  135. }
  136.  
  137. static GLboolean queryExtension(char *extName)
  138. {
  139.     /*
  140.     ** Search for extName in the extensions string.  Use of strstr()
  141.     ** is not sufficient because extension names can be prefixes of
  142.     ** other extension names.  Could use strtok() but the constant
  143.     ** string returned by glGetString can be in read-only memory.
  144.     */
  145.     char *p = (char *) glGetString(GL_EXTENSIONS);
  146.     char *end = p + strlen(p);
  147.     while (p < end) {
  148.     int n = strcspn(p, " ");
  149.     if ((strlen(extName) == n) && (strncmp(extName, p, n) == 0)) {
  150.         return GL_TRUE;
  151.     }
  152.     p += (n + 1);
  153.     }
  154.     return GL_FALSE;
  155. }
  156.  
  157. static void Init(void)
  158. {
  159.     int i;
  160.  
  161.     if (!rgb) {
  162.     SetUpColorMap();
  163.     }
  164.  
  165.     /* see if Vertex array extension is supported */
  166.     if (!queryExtension("GL_EXT_vertex_array")) {
  167.        printf("couldn't find vertex array extension\n");
  168.        tkQuit();
  169.     }
  170.  
  171.     glClearColor(0, 0, 0, 0);
  172.  
  173.     glShadeModel(GL_SMOOTH);
  174.  
  175.     /* create texture image */
  176.     for (i = 0; i < 192; i+=3) {
  177.        texture[i] = 0xff; texture[i+1] = 0xff; texture[i+2] = 0x00;
  178.     }
  179.     for (; i < 2*192; i+=3) {
  180.        texture[i] = 0xff; texture[i+1] = 0x00; texture[i+2] = 0xff;
  181.     }
  182.     for (; i < 3*192; i+=3) {
  183.        texture[i] = 0x00; texture[i+1] = 0xff; texture[i+2] = 0xff;
  184.     }
  185.     for (; i < 4*192; i+=3) {
  186.        texture[i] = 0x00; texture[i+1] = 0x00; texture[i+2] = 0xff;
  187.     }
  188. }
  189.  
  190. static void Reshape(int width, int height)
  191. {
  192.  
  193.     glMatrixMode(GL_PROJECTION);
  194.     glLoadIdentity();
  195.     glOrtho(0.0, 500.0, 0.0, 500.0, 0.0, -1000.0);
  196.     glMatrixMode(GL_MODELVIEW);
  197.     glLoadIdentity();
  198. }
  199.  
  200. static GLenum Key(int key, GLenum mask)
  201. {
  202.  
  203.     switch (key) {
  204.       case TK_a:
  205.       drawArray = !drawArray;
  206.       printf("\n ----  drawArray = %d \n\n", drawArray);
  207.       break;
  208.       case TK_d: /* toggle display lists */
  209.       dlist = !dlist;
  210.       printf("\n ----  display list = %d \n\n", dlist);
  211.       break;
  212.       case TK_m:
  213.       if (dlist) {
  214.         if (dlMode == GL_COMPILE) {
  215.           dlMode = GL_COMPILE_AND_EXECUTE;
  216.           printf("\n ----  display list mode = GL_COMPILE_AND_EXECUTE\n\n");
  217.         } else {
  218.           dlMode = GL_COMPILE;
  219.           printf("\n ----  display list mode = GL_COMPILE\n\n");
  220.         }
  221.       } else {
  222.         return GL_FALSE;
  223.       }
  224.       break;
  225.       case TK_ESCAPE:
  226.     tkQuit();
  227.       default:
  228.     printf("\n a = toggle vertex array");
  229.     printf("\n d = toggle display lists");
  230.     printf("\n m = compile or compile and execute display lists\n\n");
  231.     return GL_FALSE;
  232.     }
  233.     return GL_TRUE;
  234. }
  235.  
  236. void TestGets(void)
  237. {
  238. #if GL_EXT_vertex_array
  239.     GLint size, stride, type, count;
  240.     GLvoid *ptr;
  241.     
  242.     printf("===== Get values ======\n\n");
  243.  
  244.    printf("IsEnabled VERTEX_ARRAY_EXT = %d\n",glIsEnabled(GL_VERTEX_ARRAY_EXT));
  245.    printf("IsEnabled NORMAL_ARRAY_EXT = %d\n",glIsEnabled(GL_NORMAL_ARRAY_EXT));
  246.    printf("IsEnabled COLOR_ARRAY_EXT = %d\n",glIsEnabled(GL_COLOR_ARRAY_EXT));
  247.    printf("IsEnabled INDEX_ARRAY_EXT = %d\n",glIsEnabled(GL_INDEX_ARRAY_EXT));
  248.    printf("IsEnabled TEXTURE_COORD_ARRAY_EXT = %d\n",glIsEnabled(GL_TEXTURE_COORD_ARRAY_EXT));
  249.    printf("IsEnabled EDGE_FLAG_ARRAY_EXT = %d\n\n",glIsEnabled(GL_EDGE_FLAG_ARRAY_EXT));
  250.     CHECK_ERROR
  251.  
  252.  
  253.     glGetIntegerv(GL_VERTEX_ARRAY_SIZE_EXT, &size);
  254.     glGetIntegerv(GL_VERTEX_ARRAY_TYPE_EXT, &type);
  255.     glGetIntegerv(GL_VERTEX_ARRAY_STRIDE_EXT, &stride);
  256.     glGetIntegerv(GL_VERTEX_ARRAY_COUNT_EXT, &count);
  257.     printf("VERTEX_ARRAY size = %d, type = %d, stride = %d, count = %d\n\n",
  258.     size, type, stride, count);
  259.     CHECK_ERROR
  260.  
  261.  
  262.     glGetIntegerv(GL_NORMAL_ARRAY_TYPE_EXT, &type);
  263.     glGetIntegerv(GL_NORMAL_ARRAY_STRIDE_EXT, &stride);
  264.     glGetIntegerv(GL_NORMAL_ARRAY_COUNT_EXT, &count);
  265.     printf("NORMAL_ARRAY type = %d, stride = %d, count = %d\n\n",
  266.     type, stride, count);
  267.     CHECK_ERROR
  268.  
  269.  
  270.     glGetIntegerv(GL_COLOR_ARRAY_SIZE_EXT, &size);
  271.     glGetIntegerv(GL_COLOR_ARRAY_TYPE_EXT, &type);
  272.     glGetIntegerv(GL_COLOR_ARRAY_STRIDE_EXT, &stride);
  273.     glGetIntegerv(GL_COLOR_ARRAY_COUNT_EXT, &count);
  274.     printf("COLOR_ARRAY size = %d, type = %d, stride = %d, count = %d\n\n",
  275.     size, type, stride, count);
  276.     CHECK_ERROR
  277.  
  278.     glGetIntegerv(GL_INDEX_ARRAY_TYPE_EXT, &type);
  279.     glGetIntegerv(GL_INDEX_ARRAY_STRIDE_EXT, &stride);
  280.     glGetIntegerv(GL_INDEX_ARRAY_COUNT_EXT, &count);
  281.     printf("INDEX_ARRAY type = %d, stride = %d, count = %d\n\n",
  282.     type, stride, count);
  283.     CHECK_ERROR
  284.  
  285.  
  286.     glGetIntegerv(GL_TEXTURE_COORD_ARRAY_SIZE_EXT, &size);
  287.     glGetIntegerv(GL_TEXTURE_COORD_ARRAY_TYPE_EXT, &type);
  288.     glGetIntegerv(GL_TEXTURE_COORD_ARRAY_STRIDE_EXT, &stride);
  289.     glGetIntegerv(GL_TEXTURE_COORD_ARRAY_COUNT_EXT, &count);
  290.     printf("TEXTURE_COORD_ARRAY size = %d, type = %d, stride = %d, count = %d\n\n",
  291.     size, type, stride, count);
  292.     CHECK_ERROR
  293.  
  294.     glGetIntegerv(GL_EDGE_FLAG_ARRAY_STRIDE_EXT, &stride);
  295.     glGetIntegerv(GL_EDGE_FLAG_ARRAY_COUNT_EXT, &count);
  296.     printf("EDGE_FLAG_ARRAY stride = %d, count = %d\n\n",
  297.     stride, count);
  298.     CHECK_ERROR
  299.  
  300.     glGetPointervEXT(GL_VERTEX_ARRAY_POINTER_EXT, &ptr);
  301.     printf("VERTEX_ARRAY pointer = %x\n", ptr);
  302.     glGetPointervEXT(GL_NORMAL_ARRAY_POINTER_EXT, &ptr);
  303.     printf("NORMAL_ARRAY pointer = %x\n", ptr);
  304.     glGetPointervEXT(GL_COLOR_ARRAY_POINTER_EXT, &ptr);
  305.     printf("COLOR_ARRAY pointer = %x\n", ptr);
  306.     glGetPointervEXT(GL_INDEX_ARRAY_POINTER_EXT, &ptr);
  307.     printf("INDEX_ARRAY pointer = %x\n", ptr);
  308.     glGetPointervEXT(GL_TEXTURE_COORD_ARRAY_POINTER_EXT, &ptr);
  309.     printf("TEXTURE_COORD_ARRAY pointer = %x\n", ptr);
  310.     glGetPointervEXT(GL_EDGE_FLAG_ARRAY_POINTER_EXT, &ptr);
  311.     printf("EDGE_FLAG_ARRAY pointer = %x\n", ptr);
  312.     CHECK_ERROR;
  313. #endif
  314. }
  315.  
  316. static void Draw(void)
  317. {
  318. #if GL_EXT_vertex_array
  319.     int i;
  320.  
  321.     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  322.     glShadeModel(GL_SMOOTH);
  323.     glLineWidth(1.0);
  324.     glDisable(GL_VERTEX_ARRAY_EXT);
  325.     glDisable(GL_NORMAL_ARRAY_EXT);
  326.     glDisable(GL_COLOR_ARRAY_EXT);
  327.     glDisable(GL_INDEX_ARRAY_EXT);
  328.     glDisable(GL_TEXTURE_COORD_ARRAY_EXT);
  329.     glDisable(GL_EDGE_FLAG_ARRAY_EXT);
  330.  
  331.     glClear(GL_COLOR_BUFFER_BIT);
  332.  
  333.     /*
  334.     * Vertex and Color
  335.     */
  336.  
  337.     glVertexPointerEXT(3, GL_INT, 0, 3, verts);
  338.     glColorPointerEXT(3, GL_FLOAT, 0, 3, colors);
  339.     glEnable(GL_VERTEX_ARRAY_EXT);
  340.     glEnable(GL_COLOR_ARRAY_EXT);
  341.     CHECK_ERROR
  342.  
  343.  
  344.     if (dlist) glNewList(1, dlMode);
  345.     if (drawArray) {
  346.        glDrawArraysEXT(GL_TRIANGLES, 0, 3);
  347.     } else {
  348.         glBegin(GL_TRIANGLES);
  349.         for (i= 0; i < 3; i++) {
  350.             glArrayElementEXT(i);
  351.         }
  352.         glEnd();
  353.     }
  354.     if (dlist) {
  355.       glEndList();
  356.       glCallList(1);
  357.     }
  358.  
  359.     CHECK_ERROR
  360.  
  361.     /*
  362.     * Vertex and Color in one array
  363.     */
  364.  
  365.     glVertexPointerEXT(2, GL_FLOAT, 20, 3, &cv[3]);
  366.     glColorPointerEXT(3, GL_FLOAT, 20, 3, cv);
  367.  
  368.     if (dlist) glNewList(2, dlMode);
  369.     if (drawArray) {
  370.        glDrawArraysEXT(GL_TRIANGLES, 0, 3);
  371.     } else {
  372.         glBegin(GL_TRIANGLES);
  373.         for (i= 0; i < 3; i++) {
  374.             glArrayElementEXT(i);
  375.         }
  376.         glEnd();
  377.     }
  378.     if (dlist) {
  379.       glEndList();
  380.       glCallList(2);
  381.     }
  382.       glDisable(GL_COLOR_ARRAY_EXT);
  383.  
  384.     if (dlist) glDeleteLists(1, 2);
  385.  
  386.     /*
  387.     * Vertex and TexCoord
  388.     */
  389.  
  390.     glVertexPointerEXT(2, GL_SHORT, 8, 4, &tv[2]);
  391.     glTexCoordPointerEXT(2, GL_SHORT, 8, 4, tv);
  392.     glEnable(GL_TEXTURE_2D);
  393.     glEnable(GL_VERTEX_ARRAY_EXT);
  394.     glEnable(GL_TEXTURE_COORD_ARRAY_EXT);
  395.  
  396.     if (dlist) glNewList(3, dlMode);
  397.     glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0, GL_RGB, 
  398.         GL_UNSIGNED_BYTE, texture);
  399.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  400.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  401.  
  402.     if (drawArray) {
  403.        glDrawArraysEXT(GL_POLYGON, 0, 4);
  404.     } else {
  405.         glBegin(GL_POLYGON);
  406.         for (i= 0; i < 4; i++) {
  407.             glArrayElementEXT(i);
  408.         }
  409.         glEnd();
  410.     }
  411.     if (dlist) {
  412.       glEndList();
  413.       glCallList(3);
  414.     }
  415.     glDisable(GL_TEXTURE_2D);
  416.     glDisable(GL_TEXTURE_COORD_ARRAY_EXT);
  417.  
  418.     /*
  419.     * Vertex and EdgeFlag
  420.     */
  421.  
  422.     glEnable(GL_EDGE_FLAG_ARRAY_EXT);
  423.     glVertexPointerEXT(4, GL_FLOAT, 0, 6, verts2);
  424.     
  425.     if (dlist) glNewList(4, dlMode);
  426.  
  427.     glEdgeFlagPointerEXT(0, 6, edges);
  428.     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  429.     glShadeModel(GL_FLAT);
  430.     glLineWidth(4.0);
  431.     glColor3f(1.0, 0.0, 0.0);
  432.  
  433.     if (drawArray) {
  434.        glDrawArraysEXT(GL_POLYGON, 0, 6);
  435.     } else {
  436.         glBegin(GL_POLYGON);
  437.         for (i= 0; i < 6; i++) {
  438.             glArrayElementEXT(i);
  439.         }
  440.         glEnd();
  441.     }
  442.     if (dlist) {
  443.       glEndList();
  444.       glCallList(4);
  445.     }
  446.  
  447.     glDisable(GL_EDGE_FLAG_ARRAY_EXT);
  448.     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  449.  
  450.     /*
  451.     * Vertex and  Normal
  452.     */
  453.  
  454.     {
  455.     GLfloat back_light_pos[] = {0.0, 0.0, -1.0, 1.0};
  456.     GLfloat back_light_dir[] = {0.0, 0.0, 1.0, 1.0};
  457.     GLfloat amb[] = {0.5, 0.5, 0.5, 1.0};
  458.     GLfloat white[] = {1.0, 1.0, 1.0, 1.0};
  459.     GLfloat red[] = {1.0, 0.0, 0.0, 1.0};
  460.     GLfloat blue[] = {0.0, 0.0, 1.0, 1.0};
  461.  
  462.     glEnable(GL_LIGHTING);
  463.     glEnable(GL_LIGHT0);
  464.     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb);
  465.     glMaterialfv(GL_FRONT, GL_AMBIENT, white);
  466.     glLightfv(GL_LIGHT0, GL_DIFFUSE, red);
  467.     glEnable(GL_LIGHT1);
  468.     glLightfv(GL_LIGHT1, GL_DIFFUSE, blue);
  469.     glLightfv(GL_LIGHT1, GL_POSITION, back_light_pos);
  470.     glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, back_light_dir);
  471.  
  472.     }
  473.     glShadeModel(GL_SMOOTH);
  474.     glVertexPointerEXT(2, GL_INT, 0, 8, verts3);
  475.     glNormalPointerEXT(GL_FLOAT, 0, 8, norms);
  476.     glEnable(GL_NORMAL_ARRAY_EXT);
  477.  
  478.     if (dlist) glNewList(5, dlMode);
  479.     glBegin(GL_POLYGON);
  480.         for (i= 0; i < 4; i++) {
  481.         glArrayElementEXT(i);
  482.         }
  483.     glEnd();
  484.     glBegin(GL_POLYGON);
  485.         for (; i < 8; i++) {
  486.         glArrayElementEXT(i);
  487.         }
  488.     glEnd();
  489.  
  490.     if (dlist) {
  491.       glEndList();
  492.       glCallList(5);
  493.     }
  494.     glDisable(GL_LIGHTING);
  495.     glDisable(GL_NORMAL_ARRAY_EXT);
  496.  
  497.     /*
  498.     ** Vertex and Color (array size large enough to test RenderLarge)
  499.     */
  500.  
  501.     {
  502.     static GLfloat stripVertex[128*2][2];
  503.     static GLfloat stripColor[128*2][3];
  504.     int numSteps = 128;
  505.     int numSectors = 3;
  506.  
  507.     float stepSize = 2*M_PI / (numSteps - 1);
  508.     float sectorSize = 2*M_PI / numSectors;
  509.     float innerRadius = 40;
  510.     float outerRadius = 80;
  511.     float xCenter = 225;
  512.     float yCenter = 400;
  513.  
  514.     for (i=0; i<numSteps*2; i += 2) {
  515.         float angle = i/2 * stepSize;
  516.         float x = cos(angle);
  517.         float y = sin(angle);
  518.         float sector = angle / sectorSize;
  519.         float fade = sector - (int) sector;
  520.         float r, g, b;
  521.         stripVertex[i][0] = innerRadius * x + xCenter;
  522.         stripVertex[i][1] = innerRadius * y + yCenter;
  523.         stripVertex[i+1][0] = outerRadius * x + xCenter;
  524.         stripVertex[i+1][1] = outerRadius * y + yCenter;
  525.         switch ((int) sector) {
  526.           case 0: case 3:
  527.         /* red fade to green */
  528.         r = 1.00 * (1 - fade) + 0.25 * fade;
  529.         g = 0.25 * (1 - fade) + 1.00 * fade;
  530.         b = 0.25 * (1 - fade) + 0.25 * fade;
  531.         break;
  532.           case 1:
  533.         /* green fade to blue */
  534.         r = 0.25 * (1 - fade) + 0.25 * fade;
  535.         g = 1.00 * (1 - fade) + 0.25 * fade;
  536.         b = 0.25 * (1 - fade) + 1.00 * fade;
  537.         break;
  538.           case 2:
  539.         /* blue fade to red */
  540.         r = 0.25 * (1 - fade) + 1.00 * fade;
  541.         g = 0.25 * (1 - fade) + 0.25 * fade;
  542.         b = 1.00 * (1 - fade) + 0.25 * fade;
  543.         break;
  544.         }
  545.         stripColor[i][0] = stripColor[i+1][0] = r;
  546.         stripColor[i][1] = stripColor[i+1][1] = g;
  547.         stripColor[i][2] = stripColor[i+1][2] = b;
  548.     }
  549.  
  550.     glVertexPointerEXT(2, GL_FLOAT, 0, numSteps*2, stripVertex);
  551.     glColorPointerEXT(3, GL_FLOAT, 0, numSteps*2, stripColor);
  552.     glEnable(GL_COLOR_ARRAY_EXT);
  553.     if (dlist) glNewList(6, dlMode);
  554.         if (drawArray) {
  555.         glDrawArraysEXT(GL_TRIANGLE_STRIP, 0, numSteps*2);
  556.         } else {
  557.         glBegin(GL_TRIANGLE_STRIP);
  558.         for (i=0; i<numSteps*2; i += 2) {
  559.             glArrayElementEXT(i);
  560.             glArrayElementEXT(i+1);
  561.         }
  562.         glEnd();
  563.         }
  564.     if (dlist) {
  565.       glEndList();
  566.       glCallList(6);
  567.     }
  568.     glDisable(GL_COLOR_ARRAY_EXT);
  569.     }
  570.  
  571.     CHECK_ERROR
  572.     glFlush();
  573.     TestGets();
  574. #endif
  575. }
  576.  
  577. static GLenum Args(int argc, char **argv)
  578. {
  579.     GLint i;
  580.  
  581.     rgb = GL_TRUE;
  582.     directRender = GL_TRUE;
  583.  
  584.     for (i = 1; i < argc; i++) {
  585.     if (strcmp(argv[i], "-ci") == 0) {
  586.         rgb = GL_FALSE;
  587.     } else if (strcmp(argv[i], "-rgb") == 0) {
  588.         rgb = GL_TRUE;
  589.     } else if (strcmp(argv[i], "-dr") == 0) {
  590.         directRender = GL_TRUE;
  591.     } else if (strcmp(argv[i], "-ir") == 0) {
  592.         directRender = GL_FALSE;
  593.     } else {
  594.         printf("%s (Bad option).\n", argv[i]);
  595.         return GL_FALSE;
  596.     }
  597.     }
  598.     return GL_TRUE;
  599. }
  600.  
  601. void main(int argc, char **argv)
  602. {
  603.     GLenum type;
  604.  
  605.     if (Args(argc, argv) == GL_FALSE) {
  606.     tkQuit();
  607.     }
  608.  
  609.     tkInitPosition(0, 0, 500, 500);
  610.  
  611.     type = TK_SINGLE;
  612.     type |= (rgb) ? TK_RGB : TK_INDEX;
  613.     type |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  614.     tkInitDisplayMode(type);
  615.  
  616.     if (tkInitWindow("Test") == GL_FALSE) {
  617.     tkQuit();
  618.     }
  619.  
  620.     Init();
  621.  
  622.     tkExposeFunc(Reshape);
  623.     tkReshapeFunc(Reshape);
  624.     tkKeyDownFunc(Key);
  625.     tkDisplayFunc(Draw);
  626.     tkExec();
  627. }
  628.  
  629.